package cj.web.marriage.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriage.domain.VoteItem;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VoteItemDAO{
	
	@SQL("SELECT * FROM VoteItem WHERE deleteFlag=1 #if(:t.voteId!=-1){ AND voteId=:t.voteId } #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<VoteItem> query(@SQLParam("t") VoteItem voteItem);
		
	@SQL("SELECT count(1) FROM VoteItem WHERE deleteFlag=1 #if(:t.voteId!=-1){ AND voteId=:t.voteId } #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ")
    int querySize(@SQLParam("t") VoteItem voteItem);
    
    @SQL("select * from VoteItem where id=:1")
    VoteItem queryById(int id);
    
    @SQL("INSERT INTO VoteItem ("
			        		+ "voteId,"
			        		+ "img,"
			        		+ "name,"
			        		+ "descs,"
			        		+ "orderNo,"
			        		+ "count,"
			        		+ "status,"
			        		+ "deleteFlag,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.voteId,"
							+ ":t.img,"
							+ ":t.name,"
							+ ":t.descs,"
							+ ":t.orderNo,"
							+ "0,"
							+ "0,"
							+ "1,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()"
					+")")
    void create(@SQLParam("t") VoteItem voteItem);
	
	@SQL("UPDATE VoteItem SET "
	    			        + "voteId=:t.voteId,"
	    			        + "img=:t.img,"
	    			        + "name=:t.name,"
	    			        + "descs=:t.descs,"
	    			        + "orderNo=:t.orderNo,"
	    			        + "updateUser=:t.updateUser,"
	    			        + "updateAt=now()"
    						+ " WHERE id=:t.id")
    void update(@SQLParam("t") VoteItem voteItem);
    
    @SQL("UPDATE VoteItem SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE VoteItem SET status=1 WHERE id=:1")
    void updateBanById(int id);
    
    @SQL("UPDATE VoteItem SET status=0 WHERE id=:1")
    void updateChannelBanById(int id);
    
    @SQL("UPDATE VoteItem SET count=:2 WHERE id=:1")
    void updateCountById(int id,int count);
}